def set_stage():
""" Sets up the stage for the game """
stage.set_background("soccerfield")
stage.disable_floor()
def add_player():
""" Adds a player to the stage for the user to control """
player = codesters.Sprite("player1")
player.go_to(0, -155)
return player
def add_ball():
""" Adds a ball to the stage and sets its attributes """
def main():
""" Sets up the program and calls other functions """
set_stage()
player = add_player()
main()
t = codesters.Teacher()
defs = t.find_block("def")
sprites = stage.get_all_sprites()
sprite_lines = t.find_function("Sprite")
set_speeds = t.find_function("set_y_speed")
def get_above_def(line_number, def_list):
""" Returns the name of the nearest function and the distance above the given line number """
function_name = ""
distance = line_number - def_list[0][0]
for func in def_list:
if line_number - func[0] <= distance and line_number - func[0] > 0:
function_name = func[1]
distance = line_number - func[0]
return function_name, distance
try:
tval1 = sprite_lines[1][1].replace(' ','').lower()
tval1_line_num = sprite_lines[1][0]
tval1_indent = t.get_indent_at_line(tval1_line_num)
except:
tval1 = "DNE"
tval1_line_num = "DNE"
tval1_indent = "DNE"
try:
tval1_def, tval1_distance = get_above_def(tval1_line_num, defs)
except:
tval1_def = "DNE"
tval1_distance = "DNE"
try:
tval2 = set_speeds[0][1].replace(' ','').lower()
tval2_line_num = set_speeds[0][0]
tval2_indent = t.get_indent_at_line(tval2_line_num)
except:
tval2 = "DNE"
tval2_line_num = "DNE"
tval2_indent = "DNE"
try:
tval2_def, tval2_distance = get_above_def(tval2_line_num, defs)
except:
tval2_def = "DNE"
tval2_distance = "DNE"
t1 = TestObjective()
t1.add_success("soccerball" in tval1 and "ball=" in tval1, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add Soccer Ball inside add_ball()?")
t1.add_failure("soccerball" not in tval1, "Did you add the Soccer Ball sprite inside add_ball()?")
t1.add_failure("ball=" not in tval1, "Did you rename the sprite to ball?")
t2 = TestObjective()
t2.add_success("add_ball" in tval1_def and tval1_indent == 4, "Great job!")
t2.add_failure("add_ball" not in tval1_def, "Did you add Soccer Ball inside add_ball()?")
t2.add_failure(tval1_indent < 4 or tval1_indent > 4, "Make sure Soccer Ball is indented inside add_ball()!")
t3 = TestObjective()
t3.add_success("-8" in tval2 and "ball" in tval2, "Great job!")
t3.add_failure(tval2 == "DNE", "Did you add Set y Speed into add_ball()?")
t3.add_failure("-8" not in tval2, "Did you change the speed in set_y_speed() to -8?")
t3.add_failure("ball" not in tval2, "Did you change sprite to ball in front of set_y_speed()?")
t4 = TestObjective()
t4.add_success("add_ball" in tval2_def and tval2_indent == 4, "Great job!")
t4.add_failure("add_ball" not in tval2_def, "Did you add Set y Speed inside the add_ball() function?")
t4.add_failure(tval2_indent < 4 or tval2_indent > 4, "Make sure Set y Speed is indented inside add_ball()!")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Enviar Trabajo
-
Actividad Siguiente
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)